<template>
  <div v-loading="true" style="height:100vh"/>
</template>
<script>
import { encryption } from '@/utils';
import { getUrlInfo } from '@/api/energy';
export default {
  params() {
    return {
      query: {},
      processId: null
    };
  },
  created() {
    this.query = this.$route.query;
    this.getUrlInfo();
  },
  methods: {
    getUrlInfo() {
      const { id, type } = this.query;
      getUrlInfo({ id, type }).then(res => {
        if (res.code !== 200) {
          this.$message.error(res.message);
          this.$router.push({ name: 'overview' });
        } else {
          this.processId = res.data.processId;
          this.toJumpDetail(type);
        }
      }).catch(err => {
        console.log('err', err);
        this.toList(this.getRouteName(this.query.type));
      });
    },
    /*
    审批流类型
      0:合同审批
      1:请款审批
      2:精力分配
      3:签约内审
      4:申请原件
      5:开票申请
      6:发票作废
      7:员工报销
      8:借款申请
      9:还款申请
      11:欠款转交
      12:达人解约
      13：客户调整
      14:外采申请额度
      15:达人初筛
      16:达人上刊
    */
    getRouteName(type) {
      return {
        0: 'ContractManagement',
        2: 'energy',
        3: 'signUp',
        4: 'original',
        5: 'issueInvoice',
        6: 'invoiceAbandon',
        7: 'reimbursement',
        8: 'loan',
        9: 'payBack',
        11: 'arrearsTransfer',
        12: 'termination',
        13: 'customerAdjustment',
        14: 'externalHarvest',
        15: 'filter',
        16: 'upOnline'
      }[type];
    },
    getDetailMap(routeName) {
      const detailMap = {
        ContractManagement: {
          name: 'contractDetail',
          params: (params) => ({ id: encryption(params.id) }),
          query: (processId, params) => ({ processId: encryption(processId), ...params })
        },
        energy: {
          name: 'energyDetail',
          query: (processId, params) => ({ energyId: params.id, processId, ...params })
        },
        signUp: {
          name: 'signUpDetail',
          query: (processId, params) => ({ signUpId: params.id, processId, ...params })
        },
        original: {
          name: 'originalDetail',
          query: (processId, params) => ({ originalId: params.id, processId, ...params })
        },
        issueInvoice: {
          name: 'issueInvoiceDetail',
          query: (processId, params) => ({ issueId: params.id, processId, ...params })
        },
        invoiceAbandon: {
          name: 'invoiceAbandonDetail',
          query: (processId, params) => ({ processId, ...params })
        },
        payBack: {
          name: 'payBackDetail',
          query: (processId, params) => ({ processId, ...params })
        },
        loan: {
          name: 'loanDetail',
          query: (processId, params) => ({ processId, ...params })
        },
        reimbursement: {
          name: 'reimbursementDetail',
          query: (processId, params) => ({ reimbursementId: params.id, processId, ...params })
        },
        arrearsTransfer: {
          name: 'arrearsTransferDetail',
          query: (processId, params) => ({ processId, ...params })
        },
        termination: {
          name: 'terminationDetail',
          query: (processId, params) => ({ terminationId: params.id, processId, ...params })
        },
        customerAdjustment: {
          name: 'customerAdjustmentDetail',
          query: (processId, params) => ({ processId, ...params })
        },
        externalHarvest: {
          name: 'externalHarvestDetail',
          query: (processId, params) => ({ processId, ...params })
        },
        filter: {
          name: 'filterDetail',
          query: (processId, params) => ({ processId, ...params })
        },
        upOnline: {
          name: 'upOnlineDetail',
          query: (processId, params) => ({ processId, ...params })
        }
      };
      return detailMap[routeName];
    },
    toJumpDetail(type) {
      const params = { ...this.query };
      delete params.type;
      const userParamName = ['ContractManagement', 'energy', 'signUp', 'issueInvoice', 'original', 'reimbursement', 'termination'];// 使用param.id或者使用id别名的详情页面
      try {
        const routeName = this.getRouteName(type);
        const routeConfig = this.getDetailMap(routeName);
        routeConfig.query = routeConfig.query(this.processId, params);
        if (userParamName.includes(routeName)) {
          delete routeConfig.query.id;
        }
        if (routeConfig && routeConfig.params) {
          routeConfig.params = routeConfig.params(params);
        }
        this.$router.push(routeConfig);
      } catch (err) {
        console.log(err);
      }
    },
    toList(name) {
      this.$router.push({
        name: name
      });
    }
  }
};
</script>
